﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace FastDownload
{
    class Set
    {
        public static string Start;//是否开机启动
        public static string Auto;//是否自动开始未完成的任务
        public static string Path;//默认下载路径
        public static string Net;//网络限制下载速度
        public static string NetValue;//网速限制值
        public static string DClose;//是否下载完成自动关机
        public static string TClose;//是否定时关机
        public static string TCloseValue;//定时关机时间
        public static string SNotify;//是否显示完成显示提示
        public static string Play;//是否下载完成播放提示音
        public static string Continue;//是否在有未完成的下载时显示继续提示
        public static string ShowFlow;//是否显示流量控制
        public static string strNode = "SET";//ini文件中要读取的节点
        public static string strPath = AppDomain.CurrentDomain.BaseDirectory + "\\Set.ini";//ini配置文件路径

        [DllImport("kernel32")]//读取INI文件
        public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size,
        string filePath);
        [DllImport("kernel32")]
        public static extern long WritePrivateProfileString(string mpAppName, string mpkeyName,
            string mpDefault, string mpFileName);//向ini文件写入数据
        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
        public static extern bool ExitWindowsEx(int uFlags, int dwReserved);//定时关机
        [DllImport("ntdll.dll", ExactSpelling = true, SetLastError = true)]
        public static extern bool RtlAdjustPrivilege(int htok, bool disall, bool newst, ref int len);//关闭，重启系统拥有所有权限

        /// <summary>
        /// 从ini中读取指定的值
        /// </summary>
        /// <param name="section">ini节点</param>
        /// <param name="key">节点下的项</param>
        /// <param name="def">没有找到时返回发默认值</param>
        /// <param name="filePath">要读去的文件路径</param>
        /// <returns>返回要读取的节点内容</returns>
        public static string GetIniFileString(string section, string key, string def, string filePath)
        {
            StringBuilder temp = new StringBuilder(1024);
            GetPrivateProfileString(section, key, def, temp, 1024, filePath);
            return temp.ToString();
        }
    }

}
